<{if $shippings}>
<{if $shipping_method.shipping_id && $is_shipping_match}>
	<script>
		$('shipping_info').getParent('.link_update').show();
		$('cancel_shipping_info').fireEvent('click', $('cancel_shipping_info'));
	</script>
<{/if}>
<div id="def_shipping_info" style="padding:0" class="cancel_shipping_info hid_item"<{if !$shipping_method.shipping_id || !$is_shipping_match}> style="display:none;"<{/if}>>		
	<table width="100%" cellpadding="0" class="tableform" cellspacing="0">
		<tbody>
			<{foreach from=$shippings item="shipping" key="key" name="shippings"}>
				<{if $shipping_method.shipping_id == $shipping.dt_id}>
					<tr>
						<th ><{$shipping.dt_name}><{t}>：<{/t}><input type="hidden" class="shipping_def_dt_id" value="<{$shipping.dt_id}>" /><input type="hidden" class="shipping_def_is_protect" value="<{if $shipping.protect=='true'}>1<{else}>0<{/if}>" /></th>
						<td <{if $shipping.protect != 'true'}><{/if}>>+<{$shipping.money|cur_odr}></td>
						<{if $shipping.protect=='true'}>
						<td><label for="use_protect_<{$key}>"><{t}>保价费率<{/t}></label>
  <{t}>(商品价格的<{/t}><{$shipping.protect_rate*100}><{t}>% ，不足<{/t}><{$shipping.minprice|cur_odr}><{t}>按<{/t}><{$shipping.minprice|cur_odr}><{t}>计算)。<{/t}></td>
						<{/if}>
					</tr>
				<{/if}>
			<{/foreach}>
		</tbody>
	</table>		
</div>

<div class="hid_item shipping_info"<{if $shipping_method.shipping_id && $is_shipping_match}> style="display:none;"<{/if}>>
<table width="100%" cellpadding="0" cellspacing="0" >
            <col class="span-5"></col>
            <col class="span-auto textleft"></col>
  <tbody>
  <{foreach from=$shippings item="shipping" key="key" name="shippings"}>
  <tr <{if $smarty.foreach.shippings.last}>class="last"<{/if}>>
  <td colspan="2">
   <label style="width:auto; margin-right:10px">
    <input type="radio" name="delivery[shipping_id]" id='shipping_<{$shipping.dt_id}>' vtype="shppingradiorequired" value="<{$shipping.dt_id}>" class="toCheck shipping_radio_shipping_id"<{if $shipping.has_cod=='true'}> has_cod="true"<{/if}><{if $shipping_method.shipping_id == $shipping.dt_id}> checked="checked"<{/if}><{if $is_shipping_match == 0 && $smarty.foreach.shippings.first}> checked="checked"<{/if}><{if $shipping.protect=='true'}>protect="1"<{/if}> />
      <{$shipping.dt_name}>
    </label>
      <span style="font-size:14px;" class="fontcolorRed">+<{$shipping.money|cur_odr}></span>
      <{if $shipping.protect=='true'}>
      <div style="padding: 0 0 0 10px;">
      <input id="use_protect_<{$key}>" class="chk_protect" type="checkbox" name="delivery[is_protect][<{$shipping.dt_id}>]"<{if $shipping_method.is_protect && $shipping_method.shipping_id == $shipping.dt_id}> checked="checked" protect="1"<{/if}> value="1" />
	<{if $shipping_method.is_protect && $shipping_method.shipping_id == $shipping.dt_id}>
	<script>
		if ($('shipping')&&$('use_protect_<{$key}>'))
		{			
			$('shipping').store('tmp_protect',$('shipping_<{$shipping.dt_id}>'));			
		}
	</script>
	<{/if}>
      <label for="use_protect_<{$key}>"><{t}>保价费率<{/t}></label>
      <{t}>(商品价格的<{/t}><{$shipping.protect_rate*100}><{t}>% ，不足<{/t}><{$shipping.minprice|cur_odr}><{t}>按<{/t}><{$shipping.minprice|cur_odr}><{t}>计算)。<{/t}></div>
     <{/if}>
            <{$shipping.detail}>	
  </td>
  </tr>
  <{/foreach}>
  </tbody>
</table>
</div>
<div class="cart-ship-conf-div shipping_info hid_item"><input type="button" class="cart-btn" id="shipping_confirm" value="<{t}>确认配送方式<{/t}>" /><input type="hidden" class="cart-confirm-btn<{if !$shipping_method.shipping_id || !$is_shipping_match}> unfold<{/if}>" vtype="need_confirmed" caution='<{t}>配送方式没有确认！<{/t}>' /></div>
<{else}>
<div class='notice'><{t}>不支持您当前所在地区的物流配送，请直接与我们联系<{/t}></div>
<{/if}>
<script>
(function(){
	
	$('shipping_confirm').addEvent('click', function(el){
		// validate the purchase_info_shippping div area elements
		if ( !button_valiate.is_validate($(el.target)) )return;
		
		var ship_area = $E('input[name^=delivery[ship_area]]') ? $E('input[name^=delivery[ship_area]]').value : '';
		var _extends_args = $E('#order-create input[name^=json_extend_args]') ? $E('#order-create input[name^=json_extend_args]').value : null;
		
		new Request.HTML({
			url:Shop.url.purchase_shipping,
			update:"def_shipping_info",
			method:'post',
			data:$E('#shipping').toQueryString() + '&member_id=' + $E('input[name^=purchase[member_id]]').value + '&ship_area=' + ship_area + '&extends_args=' + _extends_args,
			onComplete:function(res){
				var _shipping_id = $E('.shipping_radio_shipping_id[checked]') ? $E('.shipping_radio_shipping_id[checked]').value : '';
				var _is_protect = 0;
				if ($E('.shipping_radio_shipping_id[checked]')){
					var checkbox = $E('.chk_protect[checked]');
					if (checkbox && !!checkbox.checked){
						_is_protect = 1;
					}
				}
				
				var _shipping_method = '{"shipping_id":"'+_shipping_id+'", "is_protect":"'+_is_protect+'"}';									
				$E('input[name^=purchase[shipping_method]]').set('value', _shipping_method);
				
				button_valiate.removeCaution($(el.target));
				$('cancel_shipping_info').fireEvent('click',$('cancel_shipping_info'));
				
				// 修改相应的支付方式
				Order.shippingChange();
			}
		}).send();
	});
	
	window.addEvent('domready', function(){
		$('shipping_info').addEvent('click', function(){
			$ES('input[name^=delivery[shipping_id]]').each(function(el){
				if ($(el).value == $E('.shipping_def_dt_id').value){
					$('shipping').fireEvent('click', el);
					if ($E('.shipping_def_is_protect') && $E('.shipping_def_is_protect').value == '1' &&$(el).getParent('td').getElement('.chk_protect')){
						$(el).getParent('td').getElement('.chk_protect').checked = true;
					}
				}
			});
		});
	});
})();
</script>